<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sloaner | 二维码生成器</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
        
        :root {
            --primary-color: #5865F2;
            --primary-dark: #4752c4;
            --secondary-color: #2ECC71;
            --secondary-dark: #27ae60;
            --text-color: #333;
            --light-text: #7b7b7b;
            --bg-color: #f7f9fc;
            --card-bg: #ffffff;
            --border-radius: 12px;
            --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
            --transition: all 0.3s ease;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Poppins', sans-serif;
            background-color: var(--bg-color);
            color: var(--text-color);
            line-height: 1.6;
            padding: 20px;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        
        .container {
            width: 100%;
            max-width: 900px;
            margin: 0 auto;
        }
        
        .header {
            text-align: center;
            margin-bottom: 40px;
            animation: fadeIn 1s ease;
        }
        
        .logo {
            display: inline-block;
            margin-bottom: 15px;
            position: relative;
        }
        
        .logo-text {
            font-size: 2.5rem;
            font-weight: 700;
            color: var(--primary-color);
            letter-spacing: -1px;
            position: relative;
            padding: 0 15px;
        }
        
        .logo-text::before {
            content: "";
            position: absolute;
            width: 45px;
            height: 45px;
            background-color: rgba(88, 101, 242, 0.15);
            border-radius: 12px;
            transform: rotate(45deg);
            z-index: -1;
            left: 0;
            top: 5px;
        }
        
        .logo-text::after {
            content: "QR";
            position: absolute;
            top: -12px;
            right: -15px;
            background-color: var(--secondary-color);
            color: white;
            font-size: 0.9rem;
            padding: 3px 8px;
            border-radius: 30px;
            font-weight: 600;
        }
        
        .header p {
            color: var(--light-text);
            font-size: 1.1rem;
            max-width: 600px;
            margin: 0 auto;
        }
        
        .card {
            background-color: var(--card-bg);
            border-radius: var(--border-radius);
            box-shadow: var(--shadow);
            padding: 30px;
            margin-bottom: 30px;
            transition: var(--transition);
        }
        
        .card:hover {
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            transform: translateY(-5px);
        }
        
        .input-section {
            margin-bottom: 30px;
        }
        
        .section-title {
            font-size: 1.2rem;
            margin-bottom: 20px;
            color: var(--text-color);
            font-weight: 600;
            display: flex;
            align-items: center;
        }
        
        .section-title::before {
            content: "";
            display: inline-block;
            width: 4px;
            height: 18px;
            background-color: var(--primary-color);
            margin-right: 10px;
            border-radius: 4px;
        }
        
        .input-container {
            display: flex;
            margin-bottom: 25px;
            position: relative;
        }
        
        #qr-text {
            flex: 1;
            padding: 15px 20px;
            border: 2px solid #eaeaea;
            border-radius: 50px;
            font-size: 16px;
            transition: var(--transition);
            font-family: 'Poppins', sans-serif;
        }
        
        #qr-text:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.2);
        }
        
        .button {
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 15px 25px;
            border-radius: 50px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 600;
            transition: var(--transition);
            font-family: 'Poppins', sans-serif;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 4px 15px rgba(88, 101, 242, 0.3);
        }
        
        .button:hover {
            background-color: var(--primary-dark);
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(88, 101, 242, 0.4);
        }
        
        .button:active {
            transform: translateY(0);
        }
        
        .generate-btn {
            margin-left: 10px;
            min-width: 140px;
        }
        
        .generate-btn::before {
            content: "";
            display: inline-block;
            width: 18px;
            height: 18px;
            background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='white'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M13 10V3L4 14h7v7l9-11h-7z'/%3E%3C/svg%3E") no-repeat center center;
            margin-right: 8px;
        }
        
        .qr-options {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin-bottom: 15px;
        }
        
        .option-group {
            display: flex;
            flex-direction: column;
        }
        
        .option-group label {
            margin-bottom: 8px;
            font-weight: 500;
            font-size: 0.9rem;
            color: var(--light-text);
        }
        
        .option-group select {
            padding: 12px 15px;
            border: 2px solid #eaeaea;
            border-radius: 8px;
            font-family: 'Poppins', sans-serif;
            transition: var(--transition);
            appearance: none;
            background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23777777'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E") no-repeat;
            background-position: right 15px center;
            background-size: 15px;
            cursor: pointer;
        }
        
        .option-group select:focus {
            outline: none;
            border-color: var(--primary-color);
        }
        
        .color-option {
            display: flex;
            align-items: center;
        }
        
        .color-preview {
            width: 30px;
            height: 30px;
            border-radius: 8px;
            margin-right: 10px;
            border: 2px solid #eaeaea;
            display: inline-block;
        }
        
        .color-picker {
            width: 0;
            height: 0;
            visibility: hidden;
            position: absolute;
        }
        
        .color-label {
            padding: 12px 15px;
            border: 2px solid #eaeaea;
            border-radius: 8px;
            font-family: 'Poppins', sans-serif;
            transition: var(--transition);
            flex: 1;
            display: flex;
            align-items: center;
            cursor: pointer;
        }
        
        .color-text {
            margin-left: 5px;
            font-size: 0.9rem;
            color: var(--light-text);
        }
        
        .output-section {
            display: flex;
            flex-direction: column;
            align-items: center;
            text-align: center;
        }
        
        #qrcode {
            margin: 20px 0;
            padding: 25px;
            background-color: white;
            border-radius: 16px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            transition: var(--transition);
            max-width: 100%;
        }
        
        #qrcode img {
            max-width: 100%;
            height: auto;
        }
        
        .action-buttons {
            display: flex;
            gap: 15px;
            margin-top: 20px;
        }
        
        .download-btn {
            background-color: var(--secondary-color);
            box-shadow: 0 4px 15px rgba(46, 204, 113, 0.3);
        }
        
        .download-btn:hover {
            background-color: var(--secondary-dark);
            box-shadow: 0 8px 20px rgba(46, 204, 113, 0.4);
        }
        
        .download-btn::before {
            content: "";
            display: inline-block;
            width: 18px;
            height: 18px;
            background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='white'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4'/%3E%3C/svg%3E") no-repeat center center;
            margin-right: 8px;
        }
        
        .output-message {
            font-size: 1.1rem;
            margin: 15px 0;
            color: var(--primary-color);
            font-weight: 500;
        }
        
        .hidden {
            display: none;
        }
        
        .footer {
            margin-top: 50px;
            text-align: center;
            color: var(--light-text);
            font-size: 0.9rem;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }
        
        .qr-loading {
            animation: pulse 1.5s infinite;
        }
        
        @media (max-width: 768px) {
            .input-container {
                flex-direction: column;
            }
            
            .generate-btn {
                margin-left: 0;
                margin-top: 15px;
                width: 100%;
            }
            
            .logo-text {
                font-size: 2rem;
            }
            
            .card {
                padding: 20px;
            }
            
            .qr-options {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <div class="logo">
                <h1 class="logo-text">sloaner</h1>
            </div>
            <p>简单、快速、美观的二维码生成工具，让信息共享变得更简单</p>
        </div>

        <div class="card input-section">
            <h2 class="section-title">创建二维码</h2>
            <div class="input-container">
                <input type="text" id="qr-text" placeholder="输入网址、文本或联系方式..." value="https://example.com">
                <button class="button generate-btn" id="generate-btn">生成二维码</button>
            </div>

            <div class="qr-options">
                <div class="option-group">
                    <label for="qr-size">尺寸大小</label>
                    <select id="qr-size">
                        <option value="128">小尺寸 (128px)</option>
                        <option value="200" selected>中等 (200px)</option>
                        <option value="300">大尺寸 (300px)</option>
                        <option value="400">超大 (400px)</option>
                    </select>
                </div>

                <div class="option-group">
                    <label for="qr-color">二维码颜色</label>
                    <div class="color-option">
                        <span class="color-preview" id="color-preview" style="background-color: #000000;"></span>
                        <label class="color-label">
                            <input type="color" id="qr-color" class="color-picker" value="#000000">
                            <span class="color-text" id="color-text">#000000</span>
                        </label>
                    </div>
                </div>

                <div class="option-group">
                    <label for="qr-bg-color">背景颜色</label>
                    <div class="color-option">
                        <span class="color-preview" id="bg-color-preview" style="background-color: #ffffff;"></span>
                        <label class="color-label">
                            <input type="color" id="qr-bg-color" class="color-picker" value="#ffffff">
                            <span class="color-text" id="bg-color-text">#FFFFFF</span>
                        </label>
                    </div>
                </div>

                <div class="option-group">
                    <label for="qr-correction">纠错级别</label>
                    <select id="qr-correction">
                        <option value="L">低 (7%)</option>
                        <option value="M" selected>中 (15%)</option>
                        <option value="Q">高 (25%)</option>
                        <option value="H">最高 (30%)</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="card output-section">
            <h2 class="section-title">您的二维码</h2>
            <div id="qrcode"></div>
            <p id="output-message" class="output-message hidden">二维码已生成，可直接长按或点击下载</p>
            <div class="action-buttons hidden" id="action-buttons">
                <button class="button download-btn" id="download-btn">下载二维码</button>
            </div>
            <canvas id="qr-canvas" class="hidden"></canvas>
        </div>
    </div>

    <div class="footer">
        <p>© 2025 Sloaner | 快速二维码生成工具</p>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const textInput = document.getElementById('qr-text');
            const generateBtn = document.getElementById('generate-btn');
            const qrcodeContainer = document.getElementById('qrcode');
            const actionButtons = document.getElementById('action-buttons');
            const outputMessage = document.getElementById('output-message');
            const downloadBtn = document.getElementById('download-btn');
            const sizeSelect = document.getElementById('qr-size');
            const colorPicker = document.getElementById('qr-color');
            const bgColorPicker = document.getElementById('qr-bg-color');
            const correctionSelect = document.getElementById('qr-correction');
            const canvas = document.getElementById('qr-canvas');
            
            // 颜色选择器相关元素
            const colorPreview = document.getElementById('color-preview');
            const colorText = document.getElementById('color-text');
            const bgColorPreview = document.getElementById('bg-color-preview');
            const bgColorText = document.getElementById('bg-color-text');
            
            let qrCode = null;
            
            // 初始生成一个示例二维码
            generateQRCode();
            
            // 点击生成按钮时生成二维码
            generateBtn.addEventListener('click', generateQRCode);
            
            // 文本输入框按下回车也触发生成
            textInput.addEventListener('keypress', function(e) {
                if (e.key === 'Enter') {
                    generateQRCode();
                }
            });
            
            // 颜色选择器更新
            colorPicker.addEventListener('input', function() {
                colorPreview.style.backgroundColor = this.value;
                colorText.textContent = this.value.toUpperCase();
                generateQRCode();
            });
            
            bgColorPicker.addEventListener('input', function() {
                bgColorPreview.style.backgroundColor = this.value;
                bgColorText.textContent = this.value.toUpperCase();
                generateQRCode();
            });
            
            // 其他选项变化时更新二维码
            sizeSelect.addEventListener('change', generateQRCode);
            correctionSelect.addEventListener('change', generateQRCode);
            
            // 下载按钮点击事件
            downloadBtn.addEventListener('click', downloadQRCode);
            
            function generateQRCode() {
                const text = textInput.value.trim();
                
                if (!text) {
                    alert('请输入文本或URL');
                    return;
                }
                
                // 显示正在生成的动画
                qrcodeContainer.innerHTML = '';
                qrcodeContainer.classList.add('qr-loading');
                
                // 获取选项值
                const size = parseInt(sizeSelect.value);
                const color = colorPicker.value;
                const bgColor = bgColorPicker.value;
                const correction = correctionSelect.value;
                
                // 创建新的二维码
                setTimeout(() => {
                    // 清除之前的二维码
                    qrcodeContainer.innerHTML = '';
                    qrcodeContainer.classList.remove('qr-loading');
                    
                    qrCode = new QRCode(qrcodeContainer, {
                        text: text,
                        width: size,
                        height: size,
                        colorDark: color,
                        colorLight: bgColor,
                        correctLevel: QRCode.CorrectLevel[correction]
                    });
                    
                    // 显示下载按钮和消息
                    actionButtons.classList.remove('hidden');
                    outputMessage.classList.remove('hidden');
                }, 500); // 添加短暂延迟，显示加载效果
            }
            
            function downloadQRCode() {
                // 获取QR码的图片
                const img = qrcodeContainer.querySelector('img');
                
                if (!img) {
                    alert('请先生成二维码');
                    return;
                }
                
                const size = parseInt(sizeSelect.value);
                
                // 创建画布并绘制二维码
                const context = canvas.getContext('2d');
                canvas.width = size;
                canvas.height = size;
                
                // 填充背景色
                context.fillStyle = bgColorPicker.value;
                context.fillRect(0, 0, canvas.width, canvas.height);
                
                // 绘制二维码图片
                context.drawImage(img, 0, 0, size, size);
                
                // 创建下载链接
                const link = document.createElement('a');
                link.download = 'sloaner-qrcode.png';
                link.href = canvas.toDataURL('image/png');
                link.click();
                
                // 显示下载成功的反馈
                const originalText = downloadBtn.textContent;
                downloadBtn.textContent = '下载成功!';
                downloadBtn.style.backgroundColor = '#27ae60';
                
                setTimeout(() => {
                    downloadBtn.textContent = originalText;
                    downloadBtn.style.backgroundColor = '';
                }, 2000);
            }
        });
    </script>
</body>
</html>
